﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LuckStar
{
    public partial class PrizeEditForm : Form
    {
        private Prize pri;
        MainForm mainform;
        public PrizeEditForm(MainForm mf,Prize _pri)
        {
            mainform = mf;
            InitializeComponent();
            pri = _pri;
            if (pri != null)
            {
                Bind();
            }//if            
        }

        private void Bind()
        {
            lb_id.Value = pri.SortID;
            lb_name.Text = pri.Name;
            lb_pname.Text = pri.PrizeName;
            lb_pic.Text = pri.Image;
            lb_Exclude.Checked = pri.IsExclude;
            lb_count.Value = pri.Count;            
        }

        private void GetPrize()
        {
            if (pri == null)
                pri = new Prize();
            pri.SortID = int.Parse(lb_id.Value.ToString());
            pri.Name = lb_name.Text.Trim();
            pri.PrizeName =lb_pname.Text.Trim();
            pri.Image = lb_pic.Text.Trim();
            pri.IsExclude = lb_Exclude.Checked;
            pri.Count = int.Parse(lb_count.Value.ToString());            
        }

        private void btn_save_Click(object sender, EventArgs e)
        {
           GetPrize();          
            mainform.SavePrize(pri);//同时刷新
            MessageBox.Show("保存成功！");
            this.Close();
        }

        private void btn_brower_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();
            of.Filter = "图片|*.jpg;*.png;*.gif;*.jpeg;*.bmp";
            of.Multiselect = false;
            if (of.ShowDialog() == DialogResult.OK)
            {
                lb_pic.Text = of.FileName;
            }
        }


    }
}
